﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class System_Admin_AdminAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void save_Click(object sender, EventArgs e)
    {
        MatchIns.Model.TAdmin admin = new MatchIns.Model.TAdmin();
        admin.UserName = username.Text.Trim();
        admin.Password = pwd.Text.Trim();
        admin.NickName = nickName.Text;

        //验证数据完整性
        errors.Items.Clear();
        if (admin.UserName.Length == 0)
            errors.Items.Add("填写用户名");
        if (admin.Password.Length == 0)
            errors.Items.Add("填写登陆密码");
        if (admin.Password != confirmPwd.Text.Trim())
            errors.Items.Add("两次密码输入不一致");

        if (errors.Items.Count != 0)
            return;
        admin.Password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(admin.Password, "MD5");
        new MatchIns.BLL.TAdmin().Add(admin);
        errors.Items.Add("用户添加成功");
        username.Text = pwd.Text = confirmPwd.Text = nickName.Text = string.Empty;
    }
    protected void cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("AdminList.aspx");
    }
}
